﻿using System;
using System.Text.RegularExpressions;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class public_html_NewSiteTest_Releaseliste : System.Web.UI.Page
{
    public string SpilID = "";
    public string Format = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        DateFromMySql NewDate = new DateFromMySql();
        string Anmeldelse = Request.QueryString["id"].ToString();
        ReviewerMySql SQL = new ReviewerMySql();
        OdbcDataReader MainReader = SQL.ExecuteReader("SELECT V2_Anmeldelse.*, V2_Distributor.Navn AS DisNavn, V2_GloFormat.Navn AS FormatNavn, V2_Spil.Format AS FormatID, V2_Spil.SpilID AS USpilID, V2_Spil.ID AS ISpilID, V2_Writters.Navn AS NavnForfatter, V2_Spil.Titel, V2_GloGenres.Navn AS Genre, V2_Spil.ID AS RealID FROM V2_Anmeldelse JOIN V2_Spil ON V2_Spil.ID = V2_Anmeldelse.SpilID JOIN V2_GloGenres ON V2_GloGenres.ID = V2_Spil.Genre JOIN V2_GloFormat ON V2_GloFormat.ID = V2_Spil.Format JOIN V2_Writters ON V2_Writters.ID = V2_Anmeldelse.Forfatter JOIN V2_Distributor ON V2_Distributor.id = V2_Anmeldelse.Dis WHERE V2_Anmeldelse.ID = " + Anmeldelse);
        MainReader.Read();

        Reviewer.Games.Games.GameCount(int.Parse(MainReader["ISpilID"].ToString()));
        
        lblTitel.Text = MainReader["Titel"].ToString();
        lblHeader.Text = MainReader["Header"].ToString();
        lblForfatter.Text = MainReader["NavnForfatter"].ToString();
        lblInfoSpil.Text = "<a href=\"" + UI.LinkMake.LinkSpil(MainReader["RealID"].ToString(), MainReader["Titel"].ToString()) + "\">Klik her for mere info</a>";
        lblDato.Text = "Lagt online d. " + NewDate.GetDate(MainReader["Dato"].ToString());

        imgKarakter.ImageUrl = "grafik/karakter" + MainReader["Karakter"].ToString() + ".png";

        OdbcDataReader SubReader = SQL.ExecuteReader("SELECT V2_Spil.*, V2_GloGenres.Navn AS GenreNavn FROM V2_Spil JOIN V2_GloGenres ON V2_GloGenres.id = V2_Spil.Genre WHERE SpilID = '" + MainReader["USpilID"].ToString() + "' AND Format = " + MainReader["FormatID"].ToString());
        SubReader.Read();

        lblFormat.Text = MainReader["FormatNavn"].ToString();
        lblMulti.Text = SubReader["Multi"].ToString();
        lblUdgiver.Text = SubReader["Udgiver"].ToString();
        lblUdvikler.Text = SubReader["Udvikler"].ToString();
        lblGenre.Text = SubReader["GenreNavn"].ToString();
        lblDis.Text = MainReader["DisNavn"].ToString();
        imgCover.Width = 200;
        imgCover.ImageUrl = "covers/" + MainReader["USpilID"].ToString() + "_" + MainReader["FormatID"].ToString() + ".jpg";

        int IntCount = 0;
        string ForTekst = Regex.Replace(MainReader["Tekst"].ToString(), Environment.NewLine, "<br />");
        string NewTekst = "";
        string[] SplTekst = Regex.Split(ForTekst, "<br /><br />");
        OdbcDataReader ScreenReader = SQL.ExecuteReader("SELECT * FROM V2_Screenshots WHERE SpilID = '" + MainReader["USpilID"].ToString() + "' AND Format = " + MainReader["FormatID"].ToString());
        foreach (string Piece in SplTekst)
        {
            if (IntCount != 4)
            {
                if (ScreenReader.Read())
                {
                    NewTekst += Piece + "<br /><center><a href=\"screenshot.aspx?PicID=" + ScreenReader["ID"].ToString() + "&SpilID=" + ScreenReader["SpilID"].ToString() + "\"><img style=\"border:1px solid black; margin:6px;\" width=\"370\" src=\"screenshots/" + ScreenReader["Filnavn"].ToString() + "\"></center></a><br />";
                }
                else
                {
                    NewTekst += Piece + "<br /><br />";
                }
            }
            else
            {
                NewTekst += Piece + "<br /><br />";
            }
            IntCount++;
        }


        lblTekst.Text = NewTekst;

        HtmlMeta HeaderDescription = new HtmlMeta();
        HeaderDescription.Name = "description";
        HeaderDescription.Content = "Anmeldelse af " + MainReader["Titel"].ToString() + " til " + MainReader["FormatNavn"].ToString() + " - " + lblHeader.Text.ToString() + "...";
        this.Header.Controls.Add(HeaderDescription);
        this.Title = "Anmeldelse af " + MainReader["Titel"].ToString() + " til " + MainReader["FormatNavn"].ToString();
    }
}
